class Auth {
    constructor() {
        this.__init.bind(this)()
    }

    async __init() {
        let a = await fetch('/login').then(v => v.json());
        this.u = a.ukey + a.sid
    }

    __des(passwd) {
        let i, p = BigInt(0);
        let u = this.u;
        let l = passwd.length;
        for (i = 0; i < u.length; i++) {
            p ^= (passwd.charCodeAt(i % l)^ u.charCodeAt(i)) << (i % 32)
        }
        return p.toString(24);
    }

    async login(user, passwd) {
        return await fetch('/login', {
            method: 'post',
            body: JSON.stringify({u: user, k: this.__des(passwd)})
        }).then(v => v.json())
    }
}


